package com.ruoyi.web.config;






import org.springframework.amqp.core.*;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {

    //交换机名称
    public static final String HS_CALLING = "hs.calling";
    //队列名称
    public static final String HS_TEST = "hs.test";

    /**
     * 实例化一个交换机
     * @return
     */
    @Bean
    public TopicExchange itemTopicExchange(){
        return ExchangeBuilder.topicExchange(HS_CALLING).durable(true).build();
    }

    /**
     * 实例化一个对列
     * @return
     */
    @Bean
    public Queue itemQueue(){
        return QueueBuilder.durable(HS_TEST).build();
    }

    @Bean
    public Binding itemQueueExchange(@Qualifier("itemQueue") Queue queue,
                                     @Qualifier("itemTopicExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("hs.#").noargs();
    }

}
